package com.redwolfsoft.libshoppingserver.brand;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class BrandStoryInfo {
	public final static String TAG = "BrandStoryInfo";
	
	//public String id = null;
	public String logoUrl = null;
	public String brandBrief = null;	
	public List<Story> storyList = null;

	
	public BrandStoryInfo(String logoUrl, String brandBrief, List<Story> list )
	{
		this.logoUrl = logoUrl;
		this.brandBrief = brandBrief;
		this.storyList = list;
	}
	
	public BrandStoryInfo(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
		//try {		
		logoUrl = obj.getString("logoUrl");
		brandBrief = obj.getString("brandBrief");
		storyList = new ArrayList<Story>();
		JSONArray array1 = obj.getJSONArray("storyList");
		for(int i=0;i<array1.size();i++)
		{				
			storyList.add(new Story(array1.getJSONObject(i)));
		}
			
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {
			obj.put("logoUrl", logoUrl);
			obj.put("brandBrief", brandBrief);
			
			JSONArray array1 = new JSONArray();
			for(int i=0;i<storyList.size();i++)
			{
				array1.add(i,storyList.get(i).toJsonObject());
			}
			obj.put("storyList", array1);	
			//obj2.put(TAG, obj);
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}*/
		return obj;
		
	}
}
